home *** CD-ROM | disk | FTP | other *** search
- /*
- PMNOS.c - (c) 1992, 1993 Walt Corey KZ1F.
- */
-
- #define INCL_WIN
- #define INCL_WINDDE
- #define INCL_WINSTDFONT
- #define INCL_DOS
- #define INCL_PMSHL
- #define INCL_DOSDEVICES
- #define INCL_DOSFILEMGR
- #define INCL_DEV
- #define INCL_GPI
- #define INCL_GPILCIDS
- #define INCL_DOSNLS
- #include <os2.h>
- #include <process.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stddef.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include "pmnos.h"
- #include "pmnosdlg.h"
- #include <stdlib.h>
- #include "global.h"
- #include "cmdparse.h"
- #include "config.h"
- #include "mbuf.h"
- #include "proc.h"
- #include "timer.h"
- #include "socket.h"
- #include "daemon.h"
- #include "hardware.h"
- #include "tty.h"
- #include "usock.h"
- #define UM_CMD WM_USER
- #define UM_SESSION WM_USER + 1
- #define UM_MAIL WM_USER + 10
- #define UM_BMAIL WM_USER + 11
- #define UM_REFRESH WM_USER + 12
- #define UM_LINK WM_USER + 13
- #define UM_MLE WM_USER + 14
- #define UM_TRACE WM_USER + 15
- #define UM_SETCURSOR WM_USER + 16
- #define UM_SETFONT WM_USER + 17
- #define UM_INSERT WM_USER + 20
- #define UM_SETFOCUS WM_USER + 21
- #define UM_SETSIZE WM_USER + 23
- #define UM_ERROR WM_USER + 107
- PFNWP pfnMle;
- PFNWP pfnEntry;
- typedef struct _pnode {
- HWND hwndClient;
- PSZ pszItem;
- } NODE, *PNODE;
- PNODE pNode1;
- #define KBSIZE 256
- extern struct cmds Cmds[],Startcmds[],Stopcmds[],Attab[];
- CONVCONTEXT convContext;
- extern int Mprunning;
- static struct {
- char buf[KBSIZE];
- char *wp;
- char *rp;
- int cnt;
- UCHAR uchScanCode;
- } Keyboard;
-
- typedef struct
- {
- long cxClient;
- long cyClient;
- HWND hwndMle;
- HWND hwndEntry;
- struct session *pSession;
- struct proc *display;
- } OBJECT, *POBJECT;
- #define ID_TIMER 1
-
- #define UM_DRAWLIST WM_USER + 2
- #define UM_SIZE_MAIL WM_USER + 3
- #define UM_DRAW_MAIL WM_USER + 4
- #define UM_SET WM_USER + 5
- #define UM_DESTROY WM_USER + 6
- #define UM_BS WM_USER + 7
- #define UM_ERASELINE WM_USER + 8
- #define BUTTON_HEIGHT 26
- #define BUTTON_WIDTH 60
- #define THREADSTACKSIZE 4096
- static VOID setupPrinter(BOOL fSetup);
- static void display(int i, void *v1, void *v2);
- void newTrace(struct session *sp);
- void freeTrace(struct session *sp);
- void MailNotify(char *pszUser);
- int nosmain(int argc, char **argv);
- int kbread(void);
- static int kbchar(void);
- extern int main_exit;
- extern struct proc Cmdpp;
- int lMleStyle;
- long lScrollWidth;
- PDDESTRUCT MakeDDEObject(PSZ pszItemName, USHORT usStatus, USHORT usFormat,
- PVOID pData, USHORT usDataLen);
-
- HWND hwndClient,
- hwndCmd,
- hwndFrame,
- hwndMainFrame,
- hwndList,
- hwndFind,
- hwndLstV,
- hwndMail,
- hwndMenu;
- static char Prompt[] = "net> ";
- static BOOL fHaveFont = FALSE;
- HMQ hmq;
- HAB hab, hab1 ;
- HINI NosIni;
- int rc;
- FATTRS fat;
- long lcid;
- PDRIVDATA pDriver;
- PSZ pszDriver;
- PSZ pszLogAddr;
- USHORT cxClient, cyClient;
- ULONG usArgc;
- CHAR **pachArgv;
- CHAR szClientClass [] = "PM NOS";
- BOOL fChanged;
- ERRORID errid;
- RECTL rectl;
- int prtError(HAB hab, HWND hwnd);
- unsigned fs;
- SWP swp;
- MRESULT EXPENTRY AboutDlgProc(HWND hDlg, ULONG msg, MPARAM mp1, MPARAM mp2);
- MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
- MRESULT EXPENTRY Dde1WndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
- MRESULT EXPENTRY DdeWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
- MRESULT EXPENTRY NewMleWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
- MRESULT EXPENTRY NewEntryWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
- static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
- FCF_MINMAX | FCF_TASKLIST | FCF_MENU |
- FCF_ICON | FCF_ACCELTABLE | FCF_SHELLPOSITION ;
- int main (int argc, char **argv);
- int main (int argc, char **argv)
- {
- QMSG qmsg;
- APIRET rc;
- PSZ pszIniPath;
- unsigned long ulSize;
- usArgc = argc;
- pachArgv = argv;
- lMleStyle = WS_VISIBLE;
- convContext.cb = sizeof(CONVCONTEXT);
- hab = WinInitialize (0) ;
- hmq = WinCreateMsgQueue (hab, 50) ;
- NosIni = (HINI)NULL;
- WinRegisterClass(hab, "DDE", DdeWndProc, 0L, sizeof(int *));
- WinRegisterClass(hab, "DDE1", Dde1WndProc, 0L, sizeof(int *));
- WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, sizeof(int *)) ;
- Keyboard.rp = Keyboard.wp = Keyboard.buf;
- lScrollWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
- pszIniPath = malloc(sizeof(FILESTATUS3));
- rc = DosQueryPathInfo("\\spool\\nos.ini", FIL_STANDARD, pszIniPath, sizeof(FILESTATUS3));
- fs = SWP_SHOW | SWP_SIZE |SWP_MOVE;
- if (rc == 0) /* ini found */
- {
- NosIni = PrfOpenProfile(hab, "\\spool\\nos.ini");
- ulSize = sizeof(RECTL);
- PrfQueryProfileData(NosIni, "NOS", "State", &rectl, &ulSize);
- ulSize = sizeof(FATTRS);
- PrfQueryProfileData(NosIni, "NOS", "Fattr", &fat, &ulSize);
- ulSize = sizeof(SWP);
- PrfQueryProfileData(NosIni, "NOS", "SWP", &swp, &ulSize);
- PrfCloseProfile(NosIni);
- fHaveFont = TRUE;
- }
- nosmain(argc, argv);
- hwndMainFrame = hwndFrame;
- flFrameFlags = FCF_TITLEBAR | FCF_SIZEBORDER |
- FCF_MINMAX | FCF_TASKLIST |
- FCF_ICON | FCF_SHELLPOSITION | FCF_ACCELTABLE ;
-
- hwndMenu = WinWindowFromID(hwndMainFrame, FID_MENU);
- if (NosIni == (HINI)NULL)
- {
- rectl.xLeft = 0L;
- rectl.yBottom = 0L;
- rectl.xRight = fat.lAveCharWidth * 81L + lScrollWidth;
- rectl.yTop = fat.lMaxBaselineExt * 25L;
- WinCalcFrameRect(hwndFrame, &rectl, FALSE);
- }
- else
- {
- rectl.xLeft = swp.x;
- rectl.yBottom = swp.y;
- rectl.xRight = swp.cx;
- rectl.yTop = swp.cy;
- }
- WinPostMsg(hwndCmd, UM_SETSIZE, 0L, 0L);
- Mprunning = TRUE;
- while (WinGetMsg (hab, &qmsg, (HWND)NULL, 0L, 0L))
- WinDispatchMsg (hab, &qmsg);
- WinQueryWindowPos(hwndFrame, &swp);
- NosIni = PrfOpenProfile(hab, "\\spool\\nos.ini");
- PrfWriteProfileData(NosIni, "NOS", "State", &rectl, sizeof(RECTL));
- PrfWriteProfileData(NosIni, "NOS", "Fattr", &fat, sizeof(FATTRS));
- PrfWriteProfileData(NosIni, "NOS", "SWP", &swp, sizeof(SWP));
- PrfCloseProfile(NosIni);
- WinDestroyWindow (hwndFrame);
- WinDestroyMsgQueue (hmq);
- WinTerminate (hab);
- return 0;
- }
-
- MRESULT EXPENTRY DdeWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- ULONG dwTime;
- PDDESTRUCT pddes;
- QMSG qmsg;
- PNODE pNode;
- PCREATESTRUCT pCreate;
- switch (msg)
- {
- case UM_MAIL:
- pNode = (PNODE)WinQueryWindowULong(hwnd, 0);
- if (pNode && pNode->pszItem && (strcmp(pNode->pszItem, PVOIDFROMMP(mp1)) == 0))
- {
- pddes = MakeDDEObject(pNode->pszItem,
- DDE_FNODATA,
- DDEFMT_TEXT,
- NULL,
- 0);
- WinDdePostMsg(pNode->hwndClient, hwnd, WM_DDE_DATA, pddes, DDEPM_RETRY);
- }
- break;
-
- case WM_CREATE:
- if (!WinIsWindow(hab, pNode1->hwndClient))
- return((MRESULT)TRUE);
- WinSetWindowULong(hwnd, 0, (ULONG)pNode1);
- WinDdeRespond(pNode1->hwndClient, hwnd, "PMNOS", "MAIL", &convContext);
- if (pNode1->pszItem)
- free(pNode->pszItem);
- break;
-
- case WM_DESTROY:
- pNode = (PNODE)WinQueryWindowULong(hwnd, 0);
- if (pNode->hwndClient)
- {
- WinDdePostMsg(pNode->hwndClient, hwnd, WM_DDE_TERMINATE, 0L, DDEPM_RETRY);
- dwTime = WinGetCurrentTime (hab) ;
- while (WinGetCurrentTime (hab) - dwTime < 3000)
- if (WinPeekMsg (hab, &qmsg, hwnd, WM_DDE_TERMINATE,
- WM_DDE_TERMINATE, PM_REMOVE))
- break ;
- }
- if (pNode->pszItem)
- free(pNode->pszItem);
- free(pNode);
- break;
-
- case WM_DDE_ADVISE:
- pNode = (PNODE)WinQueryWindowULong(hwnd, 0);
- pddes = PVOIDFROMMP(mp2);
- if (pNode->pszItem)
- free(pNode->pszItem);
- pNode->pszItem = strdup(DDES_PSZITEMNAME((PDDESTRUCT)mp2));
- DosFreeMem(PVOIDFROMMP(mp2));
- break;
-
- case WM_DDE_UNADVISE:
- pNode = (PNODE)WinQueryWindowULong(hwnd, 0);
- pddes = PVOIDFROMMP(mp2);
- if (pNode->pszItem)
- free(pNode->pszItem);
- pNode->pszItem = NULL;
- DosFreeMem(PVOIDFROMMP(mp2));
- break;
-
- case WM_DDE_TERMINATE:
- pNode = (PNODE)WinQueryWindowULong(hwnd, 0);
- if (pNode->hwndClient)
- WinDdePostMsg(pNode->hwndClient, hwnd, WM_DDE_TERMINATE, 0L, DDEPM_RETRY);
- pNode->hwndClient = (HWND)NULL;
- WinDestroyWindow(hwnd);
- break;
-
- default:
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));
- }
- return((MRESULT)NULL);
- }
-
- MRESULT EXPENTRY Dde1WndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- PNODE pNode;
- ULONG dwTime;
- PDDESTRUCT pddes;
- QMSG qmsg;
- pNode = (PNODE)WinQueryWindowULong(hwnd, 0);
- switch (msg)
- {
- case WM_CREATE:
- pNode = (PNODE)PVOIDFROMMP(mp1);
- WinSetWindowULong(hwnd, 0, (ULONG)pNode);
- free(pNode->pszItem);
- break;
-
- case WM_DESTROY:
- if (pNode->hwndClient)
- {
- WinDdePostMsg(pNode->hwndClient, hwnd, WM_DDE_TERMINATE, 0L, DDEPM_RETRY);
- dwTime = WinGetCurrentTime (hab) ;
- while (WinGetCurrentTime (hab) - dwTime < 3000)
- if (WinPeekMsg (hab, &qmsg, hwnd, WM_DDE_TERMINATE,
- WM_DDE_TERMINATE, PM_REMOVE))
- break ;
- }
- if (pNode->pszItem)
- free(pNode->pszItem);
- free(pNode);
- break;
-
- case WM_DDE_ADVISE:
- pddes = PVOIDFROMMP(mp2);
- if (pNode->pszItem)
- free(pNode->pszItem);
- pNode->pszItem = strdup(DDES_PSZITEMNAME((PDDESTRUCT)mp2));
- DosFreeMem(PVOIDFROMMP(mp2));
- break;
-
- case WM_DDE_UNADVISE:
- pddes = PVOIDFROMMP(mp2);
- if (pNode->pszItem)
- free(pNode->pszItem);
- pNode->pszItem = NULL;
- DosFreeMem(PVOIDFROMMP(mp2));
- break;
-
- case WM_DDE_TERMINATE:
- if (pNode->hwndClient)
- WinDdePostMsg(pNode->hwndClient, hwnd, WM_DDE_TERMINATE, 0L, DDEPM_RETRY);
- pNode->hwndClient = (HWND)NULL;
- WinDestroyWindow(hwnd);
- break;
-
- default:
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));
- }
- return((MRESULT)NULL);
- }
-
-
-
- MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- ULONG rc, usInfo, usResult;
- PSZ pszName;
- MRESULT mrResult;
- PDDEINIT pddeInit;
- HPS hps;
- PFONTMETRICS pFontMetrics;
- LONG cfm, nFonts, lHorzRes, lVertRes;
- USHORT i;
- BOOL fFontNotFound, f8PtNotFound;
- HDC hdcTmp;
- POWNERITEM poi;
- BOOL fErr;
- LONG lErr;
- PSZ pszText;
- POBJECT pObject;
- struct mbuf *bp;
- struct session *sp;
- ULONG ulPostCt, ulCharCnt, cy;
- ERRORID err;
- PERRINFO pErr;
- SWP swp;
- PFONTDLG pFont;
- PSZ pFamily;
- HWND hDlg;
- EXCEPTIONREPORTRECORD *pException;
- struct proc *tmpProc;
- switch (msg)
- {
- case WM_CREATE:
- pObject = malloc(sizeof(OBJECT));
- memset(pObject, '\0', sizeof(OBJECT));
- WinSetWindowULong(hwnd, 0, (ULONG)pObject);
- if (!fHaveFont)
- {
- /*
- Create special font
- */
- hps = WinGetPS(hwnd);
- hdcTmp = GpiQueryDevice(hps);
- DevQueryCaps(hdcTmp,
- CAPS_HORIZONTAL_FONT_RES,
- 1L,
- (PLONG)&lHorzRes);
- DevQueryCaps(hdcTmp,
- CAPS_VERTICAL_FONT_RES,
- 1L,
- (PLONG)&lVertRes);
- cfm = 0L;
- nFonts = GpiQueryFonts(hps,
- QF_PUBLIC,
- "Courier",
- &cfm,
- 0L,
- NULL);
- pFontMetrics = malloc(nFonts * sizeof(FONTMETRICS));
- GpiQueryFonts(hps,
- QF_PUBLIC,
- "Courier",
- &nFonts,
- (LONG)sizeof(FONTMETRICS),
- pFontMetrics);
- fFontNotFound = f8PtNotFound = TRUE;
- for (i = 0; (i < (USHORT)nFonts) && fFontNotFound; i++)
- {
- /* We are looking for a fixed font type */
- if ((pFontMetrics[i].fsType & FM_TYPE_FIXED) == 0)
- continue;
-
- /* We are further looking for a non-vectored font */
-
- if ((pFontMetrics[i].fsDefn & FM_DEFN_OUTLINE))
- continue;
-
- /* We are further looking for an appropriate resolution */
-
- if ((pFontMetrics[i].sXDeviceRes != (SHORT)lHorzRes) ||
- (pFontMetrics[i].sYDeviceRes != (SHORT)lVertRes))
- continue;
-
- fFontNotFound = FALSE;
- }
- i--;
- /* set up for using it */
- memset((char *)&fat, '\0', sizeof(FATTRS));
- fat.usRecordLength = sizeof(fat);
- strcpy((char *)fat.szFacename, (char *)"Courier" );
- if (!fFontNotFound)
- {
- fat.fsSelection = pFontMetrics[i].fsSelection;
- fat.lMatch = pFontMetrics[i].lMatch;
- strcpy((char *)fat.szFacename, (char *)pFontMetrics[i].szFacename );
- fat.idRegistry = pFontMetrics[i].idRegistry;
- fat.usCodePage = (USHORT)GpiQueryCp(hps);
- fat.lMaxBaselineExt = pFontMetrics[i].lMaxBaselineExt;
- fat.lAveCharWidth = pFontMetrics[i].lAveCharWidth;
- }
- if (rc != 2)
- prtError(hab, hwnd);
- WinReleasePS(hps);
- free((char *)pFontMetrics);
- }
- fHaveFont = TRUE;
- break;
-
- case WM_SAVEAPPLICATION:
- WinQueryWindowPos(hwndMainFrame, &swp);
- NosIni = PrfOpenProfile(hab, "\\spool\\nos.ini");
- PrfWriteProfileData(NosIni, "NOS", "State", &rectl, sizeof(RECTL));
- PrfWriteProfileData(NosIni, "NOS", "Fattr", &fat, sizeof(FATTRS));
- PrfWriteProfileData(NosIni, "NOS", "SWP", &swp, sizeof(SWP));
- PrfCloseProfile(NosIni);
- return(WinDefWindowProc(hwnd, msg, mp1, mp2));
- break;
-
- case UM_SETSIZE:
- WinSetWindowPos(hwndFrame,
- HWND_TOP,
- rectl.xLeft,
- rectl.yBottom,
- rectl.xRight,
- rectl.yTop,
- NosIni ? fs : (SWP_SHOW | SWP_SIZE));
- break;
-
- case UM_LINK:
- WinDdeInitiate(hwnd, "", "MAIL", &convContext);
- break;
-
- case WM_DDE_INITIATE:
- pddeInit = PVOIDFROMMP(mp2);
- if (HWNDFROMMP(mp1) == hwnd)
- break;
- if ((strcmp("PMNOS", pddeInit->pszAppName) == 0) &&
- (strlen(pddeInit->pszTopic) == 0 ||
- (strcmp("MAIL", pddeInit->pszTopic) == 0)))
- {
- pNode1 = malloc(sizeof(NODE));
- if(!pNode1)
- break;
- memset(pNode1, '\0', sizeof(NODE));
- pNode1->hwndClient = HWNDFROMMP(mp1);
- WinCreateWindow(hwnd,
- "DDE",
- "",
- 0L,
- 0, 0, 0, 0,
- hwnd,
- HWND_TOP,
- 1,
- pNode1,
- NULL);
- }
- break;
-
- case UM_BMAIL:
- err = WinGetLastError(hab);
- rc = WinBroadcastMsg(hwndMainFrame, UM_MAIL, mp1,
- 0L, BMSG_DESCENDANTS | BMSG_SEND);
- free(mp1);
- break;
-
- case UM_SESSION:
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- sp = PVOIDFROMMP(mp1);
- if (!sp->name)
- sp->name = strdup("Unknown peer");
- pszName = malloc(strlen(sp->name) + strlen(szClientClass) + 4);
- strcpy(pszName, szClientClass);
- strcat(pszName, " - ");
- strcat(pszName, sp->name);
- if (sp != NULLSESSION)
- {
- sp->hwndFrame = WinCreateStdWindow (HWND_DESKTOP,
- 0,
- &flFrameFlags,
- szClientClass,
- pszName,
- 0,
- (HMODULE)NULL,
- ID_RESOURCE,
- &sp->hwndSession);
- if (!sp->hwndFrame)
- {
- prtError(hab, hwnd);
- break;
- }
- pObject = (POBJECT)WinQueryWindowULong(sp->hwndSession, 0);
- WinSetWindowPos(sp->hwndFrame,
- HWND_TOP,
- rectl.xLeft,
- rectl.yBottom,
- rectl.xRight,
- rectl.yTop,
- SWP_SHOW | SWP_SIZE);
- WinQueryWindowPos(sp->hwndSession, &swp);
- cy = 0;
- if (sp->split)
- cy = (ULONG)((double)fat.lMaxBaselineExt * 1.25);
- pObject->hwndMle = WinCreateWindow(sp->hwndSession,
- WC_MLE,
- "",
- WS_VISIBLE | MLS_VSCROLL |MLS_WORDWRAP,
- 0, cy, swp.cx, swp.cy - cy,
- sp->hwndSession,
- HWND_TOP,
- 1,
- NULL,
- NULL);
- if (!pObject->hwndMle)
- {
- prtError(hab, hwnd);
- break;
- }
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETFONT, MPFROMP(&fat), 0L);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETTABSTOP, MPFROMSHORT(8 *(short)fat.lAveCharWidth), 0L);
- if (rc == 0)
- prtError(hab, hwnd);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETBACKCOLOR, MPFROMLONG(CLR_BACKGROUND), 0L);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETTEXTLIMIT, MPFROMLONG(-1), 0L);
- if (sp->split)
- {
- pObject->hwndEntry = WinCreateWindow(sp->hwndSession,
- WC_ENTRYFIELD,
- "",
- WS_VISIBLE | ES_AUTOSCROLL,
- 0,0, swp.cx, cy,
- sp->hwndSession,
- HWND_TOP,
- 12,
- NULL,
- NULL);
-
- rc = (int)WinSendMsg(pObject->hwndEntry, EM_SETTEXTLIMIT, MPFROMSHORT(256), 0L);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETREADONLY, MPFROMSHORT(1), 0L);
- pfnEntry = WinSubclassWindow(pObject->hwndEntry, NewEntryWndProc);
- rc = WinSetFocus(HWND_DESKTOP, pObject->hwndEntry);
- }
- else
- rc = WinSetFocus(HWND_DESKTOP, pObject->hwndMle);
- if (rc == 0)
- prtError(hab, hwnd);
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- pfnMle = WinSubclassWindow(pObject->hwndMle, NewMleWndProc);
- pObject->pSession = sp;
- free(pszName);
- sp->screen = callocw(1,sizeof(struct screen));
- sp->ttystate.crnl = sp->ttystate.edit = sp->ttystate.echo = 1;
- sp->flowmode = 0; /* Off by default */
- sp->row = MOREROWS;
- sp->morewait = 0;
- pObject->display = sp->display = newproc("display", 4096, display, 1, pObject->pSession, NULL, 0);
- }
- if (mp2)
- DosPostEventSem(Curproc->sem);
- break;
-
- case UM_ERROR:
- pszText = malloc(64);
- pException = (EXCEPTIONREPORTRECORD *)mp2;
- tmpProc = (struct proc *)mp1;
- sprintf(pszText, "Exception occurred at %8x in %s", pException->ExceptionAddress, ((struct proc *)mp1)->name);
- WinMessageBox(HWND_DESKTOP, hwnd, pszText, "PMNOS Error", 0, MB_ICONEXCLAMATION | MB_OK);
- free(pszText);
- free(mp1);
- free(mp2);
- break;
-
- case UM_SETFONT:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- if (pObject->hwndMle)
- WinSendMsg(pObject->hwndMle, MLM_SETFONT, mp1, mp2);
- break;
- case UM_TRACE:
- sp = PVOIDFROMMP(mp1);
- pszName = malloc(strlen(sp->name) + strlen(szClientClass) + 4);
- strcpy(pszName, szClientClass);
- strcat(pszName, " - ");
- strcat(pszName, sp->name);
- if (sp != NULLSESSION)
- {
- sp->type = TRACESESSION;
- sp->hwndFrame = WinCreateStdWindow (HWND_DESKTOP,
- 0,
- &flFrameFlags,
- szClientClass,
- pszName,
- 0,
- (HMODULE)NULL,
- ID_RESOURCE,
- &sp->hwndSession);
- if (!sp->hwndFrame)
- {
- prtError(hab, hwnd);
- break;
- }
- pObject = (POBJECT)WinQueryWindowULong(sp->hwndSession, 0);
- WinSetWindowPos(sp->hwndFrame,
- HWND_TOP,
- rectl.xLeft,
- rectl.yBottom,
- rectl.xRight,
- rectl.yTop,
- SWP_SHOW | SWP_SIZE);
- WinQueryWindowPos(sp->hwndSession, &swp);
- pObject->hwndMle = WinCreateWindow(sp->hwndSession,
- WC_MLE,
- "",
- MLS_VSCROLL,
- 0, 0, swp.cx, swp.cy,
- sp->hwndSession,
- HWND_TOP,
- 1,
- NULL,
- NULL);
- if (!pObject->hwndMle)
- {
- prtError(hab, hwnd);
- break;
- }
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETFONT, MPFROMP(&fat), 0L);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETTABSTOP, MPFROMSHORT(8 *(short)fat.lAveCharWidth), 0L);
- if (rc == 0)
- prtError(hab, hwnd);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETBACKCOLOR, MPFROMLONG(CLR_BACKGROUND), 0L);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETTEXTLIMIT, MPFROMLONG(-1), 0L);
- pObject = (POBJECT)WinQueryWindowULong(sp->hwndSession, 0);
- pObject->pSession = sp;
- WinShowWindow(pObject->hwndMle, TRUE);
- rc = WinSetFocus(HWND_DESKTOP, pObject->hwndMle);
- if (rc == 0)
- prtError(hab, hwnd);
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- free(pszName);
- DosPostEventSem(Curproc->sem);
- }
- break;
-
- case WM_SIZE:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- pObject->cxClient = SHORT1FROMMP(mp2);
- pObject->cyClient = SHORT2FROMMP(mp2);
- if (pObject->hwndEntry)
- {
- WinSetWindowPos(pObject->hwndEntry,
- HWND_TOP,
- 0, 0,
- pObject->cxClient, fat.lMaxBaselineExt,
- SWP_SIZE);
- WinSetWindowPos(pObject->hwndMle,
- HWND_TOP,
- 0, fat.lMaxBaselineExt,
- pObject->cxClient, pObject->cyClient - fat.lMaxBaselineExt,
- SWP_SIZE);
- }
- else
- WinSetWindowPos(pObject->hwndMle,
- HWND_TOP,
- 0, 0,
- pObject->cxClient, pObject->cyClient,
- SWP_SIZE);
- break;
-
- case UM_REFRESH:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- if (!pObject->hwndMle)
- break;
- if (mp1)
- WinSendMsg(pObject->hwndMle, MLM_ENABLEREFRESH, 0L, 0L);
- else
- WinSendMsg(pObject->hwndMle, MLM_DISABLEREFRESH, 0L, 0L);
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- break;
-
- case UM_BS:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- mrResult = WinSendMsg(pObject->hwndMle, MLM_QUERYTEXTLENGTH, MPFROMLONG(0L), MPFROMLONG(0L));
- ulCharCnt = LONGFROMMR(mrResult);
- WinSendMsg(pObject->hwndMle, MLM_DELETE, MPFROMLONG(ulCharCnt), MPFROMLONG(1L));
- break;
-
-
- case UM_ERASELINE:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- mrResult = WinSendMsg(pObject->hwndMle, MLM_QUERYTEXTLENGTH, MPFROMLONG(0L), MPFROMLONG(0L));
- ulCharCnt = LONGFROMMR(mrResult);
- mrResult = WinSendMsg(pObject->hwndMle, MLM_CHARFROMLINE, MPFROMLONG(-1L), MPFROMLONG(0L));
- ulCharCnt -= LONGFROMMR(mrResult);
- WinSendMsg(pObject->hwndMle, MLM_DELETE, (MPARAM)mrResult, MPFROMLONG(ulCharCnt + 1));
- break;
-
- case MLM_INSERT:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- mrResult = WinSendMsg(pObject->hwndMle, MLM_QUERYTEXTLENGTH, MPFROMLONG(0L), MPFROMLONG(0L));
- ulCharCnt = LONGFROMMR(mrResult);
- WinSendMsg(pObject->hwndMle, MLM_SETSEL, MPFROMLONG(ulCharCnt), MPFROMLONG(ulCharCnt));
- if (mp2)
- {
- WinSendMsg(pObject->hwndMle, msg, mp1, 0L);
- free(PVOIDFROMMP(mp1));
- }
- else
- WinSendMsg(pObject->hwndMle, msg, mp1, mp2);
- break;
-
- case UM_INSERT:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- if (!pObject->pSession->split)
- break;
- mrResult = WinSendMsg(pObject->hwndMle, MLM_QUERYTEXTLENGTH, MPFROMLONG(0L), MPFROMLONG(0L));
- ulCharCnt = LONGFROMMR(mrResult);
- WinSendMsg(pObject->hwndMle, MLM_SETSEL, MPFROMLONG(ulCharCnt), MPFROMLONG(ulCharCnt));
- if (mp2)
- {
- WinSendMsg(pObject->hwndMle, MLM_INSERT, mp1, 0L);
- free(PVOIDFROMMP(mp1));
- }
- else
- WinSendMsg(pObject->hwndMle, MLM_INSERT, mp1, mp2);
- break;
-
- case UM_DESTROY:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- rc = WinDestroyWindow(pObject->pSession->hwndFrame);
- if (rc == 0)
- prtError(hab, hwnd);
- break;
-
-
- case WM_DESTROY:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- free(pObject);
- break;
-
- case WM_CLOSE:
- if (!main_exit)
- {
- Keyboard.rp = Keyboard.wp = Keyboard.buf;
- strcpy(Keyboard.buf, "exit\n");
- Keyboard.cnt = 5;
- psignal(&Keyboard, 0);
- }
- else
- WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- break;
-
- case WM_CONTROL:
- pObject = (POBJECT)WinQueryWindowULong(hwnd, 0);
- switch (SHORT2FROMMP(mp1))
- {
- case MLN_CHANGE:
- if (SHORT1FROMMP(mp1) == 1 || SHORT1FROMMP(mp1) == 12)
- WinPostMsg(WinQueryCapture(HWND_DESKTOP), WM_MOUSEMOVE, MPFROM2SHORT(100,100), 0L);
- break;
-
- case MLN_OVERFLOW:
- case MLN_TEXTOVERFLOW:
- case MLN_MEMERROR:
- if(SHORT1FROMMP(mp1) != 1) /* not our mle entry field */
- break;
- WinSendMsg(pObject->hwndMle, MLM_DISABLEREFRESH, 0L, 0L);
- i = (int)WinSendMsg(pObject->hwndMle, MLM_QUERYLINECOUNT, 0L, 0L);
- i /= 2;
- i = (int)WinSendMsg(pObject->hwndMle, MLM_CHARFROMLINE, MPFROMLONG(i), 0L);
- WinSendMsg(pObject->hwndMle, MLM_SETSEL, 0L, MPFROMLONG(i));
- WinSendMsg(pObject->hwndMle, MLM_CLEAR, 0L, 0L);
- mrResult = WinSendMsg(pObject->hwndMle, MLM_QUERYTEXTLENGTH, MPFROMLONG(0L), MPFROMLONG(0L));
- ulCharCnt = LONGFROMMR(mrResult);
- WinSendMsg(pObject->hwndMle, MLM_SETSEL, MPFROMLONG(ulCharCnt), MPFROMLONG(ulCharCnt));
- WinSendMsg(pObject->hwndMle, MLM_ENABLEREFRESH, 0L, 0L);
- break;
- default:
- return(MRFROMSHORT(TRUE));
- }
- break;
-
- case WM_COMMAND:
- switch (SHORT1FROMMP(mp1))
- {
- case IDM_FONT:
- pFont = malloc(sizeof(FONTDLG));
- pFamily = malloc(64);
- memset(pFont, '\0', sizeof(FONTDLG));
- pFont->cbSize = sizeof(FONTDLG);
- pFont->hpsScreen = WinGetPS(hwnd);
- pFont->pszFamilyname = pFamily;
- strcpy(pFamily, "Courier");
- pFont->usFamilyBufLen = strlen(pFamily);
- pFont->pszTitle = "PM NOS Setup";
- pFont->fl = FNTS_CENTER | FNTS_INITFROMFATTRS;
- pFont->clrFore = CLR_BLACK;
- pFont->clrBack = CLR_WHITE;
- pFont->usWeight = FWEIGHT_NORMAL;
- pFont->usWidth = FWIDTH_NORMAL;
- pFont->fxPointSize = MAKEFIXED(8,0);
- memcpy(&pFont->fAttrs, &fat, sizeof(FATTRS));
- hDlg = WinFontDlg(HWND_DESKTOP, hwnd, pFont);
- WinReleasePS(pFont->hpsScreen);
- if (hDlg && (pFont->lReturn == DID_OK))
- {
- memcpy(&fat, &pFont->fAttrs, sizeof(FATTRS));
- rc = WinBroadcastMsg(hwndMainFrame, UM_SETFONT, MPFROMP(&fat),
- 0L, BMSG_DESCENDANTS | BMSG_SEND);
- }
- free(pFont);
- free(pFamily);
- break;
-
- case IDM_ABOUT:
- WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc,
- (HMODULE)NULL, IDD_ABOUT, NULL);
- break;
- }
- break;
-
- default:
- return WinDefWindowProc (hwnd, msg, mp1, mp2);
- }
- return (MRFROMSHORT(0));
- }
-
-
- MRESULT EXPENTRY AboutDlgProc(HWND hDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
- /*
- About... dialog procedure
- */
- {
- switch(msg)
- {
- case WM_COMMAND:
- switch(SHORT1FROMMP(mp1))
- {
- case DID_OK:
- case DID_CANCEL:
- WinDismissDlg(hDlg, TRUE);
- break;
-
- default:
- break;
- }
- break;
- default:
- return WinDefDlgProc(hDlg, msg, mp1, mp2);
-
- }
- return MRFROMSHORT(FALSE);
- }
-
- MRESULT EXPENTRY NewMleWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- USHORT fsKeyFlags, usChar, usVKey;
- UCHAR uchRepeat;
- HWND hwndParent;
- POBJECT pObject;
- MRESULT mrResult;
- ULONG ulCharCnt;
-
- hwndParent = WinQueryWindow(hwnd, QW_PARENT);
- pObject = (POBJECT)WinQueryWindowULong(hwndParent, 0);
-
- switch(msg)
- {
- case WM_SETFOCUS:
- if (SHORT1FROMMP(mp2))
- {
- Lastcurr = Current;
- Current = pObject->pSession;
- if(pObject->hwndEntry)
- {
- WinAlarm(HWND_DESKTOP, WA_WARNING);
- WinPostMsg(pObject->hwndEntry, UM_SETFOCUS, MPFROMHWND(pObject->hwndEntry), MPFROMSHORT(TRUE));
- }
- else
- {
- mrResult = WinSendMsg(hwnd, MLM_QUERYTEXTLENGTH, MPFROMLONG(0L), MPFROMLONG(0L));
- ulCharCnt = LONGFROMMR(mrResult);
- WinSendMsg(hwnd, MLM_SETSEL, MPFROMLONG(ulCharCnt + 300), MPFROMLONG(ulCharCnt + 300));
- WinPostMsg(hwnd, WM_MOUSEMOVE, MPFROM2SHORT(20,20), 0L);
- WinPostMsg(hwnd, WM_BUTTON1DOWN, MPFROM2SHORT(1,100), 0L);
- WinPostMsg(hwnd, WM_BUTTON1UP, MPFROM2SHORT(1,100), 0L);
- }
- }
- return((pfnMle)(hwnd, msg, mp1, mp2));
-
- case WM_CHAR:
- if (pObject->hwndEntry)
- return(MPFROMSHORT(TRUE));
- fsKeyFlags = (USHORT)SHORT1FROMMP(mp1);
- uchRepeat = (UCHAR)CHAR3FROMMP(mp1);
- Keyboard.uchScanCode = (UCHAR)CHAR4FROMMP(mp1);
- usChar = (USHORT)SHORT1FROMMP(mp2);
- usVKey = (USHORT)SHORT2FROMMP(mp2);
- if (!(fsKeyFlags & KC_KEYUP))
- if ((fsKeyFlags & KC_CHAR))
- {
- while (uchRepeat--)
- {
- *Keyboard.wp++ = usChar;
- if(Keyboard.wp == &Keyboard.buf[KBSIZE])
- Keyboard.wp = Keyboard.buf;
- Keyboard.cnt++;
- psignal(&Keyboard,0);
- }
- if(!Current->ttystate.echo)
- return(MRFROMSHORT(TRUE));
- }
- else
- if (fsKeyFlags & KC_CTRL && (usChar & 0xff))
- {
- usChar &= 0xdf; /* make uppercase */
- *Keyboard.wp++ = usChar - 0x40;
- if(Keyboard.wp == &Keyboard.buf[KBSIZE])
- Keyboard.wp = Keyboard.buf;
- Keyboard.cnt++;
- psignal(&Keyboard,0);
- }
- else
- if (fsKeyFlags & KC_VIRTUALKEY && ((usChar & 0x1b) == 0x1b))
- {
- *Keyboard.wp++ = 0x1b;
- if(Keyboard.wp == &Keyboard.buf[KBSIZE])
- Keyboard.wp = Keyboard.buf;
- Keyboard.cnt++;
- psignal(&Keyboard,0);
- }
-
- return((MRESULT)(pfnMle)(hwnd, msg, mp1, mp2));
-
- default:
- return((pfnMle)(hwnd, msg, mp1, mp2));
- }
- return((MRESULT)FALSE);
- }
-
- MRESULT EXPENTRY NewEntryWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
- USHORT fsKeyFlags, usChar, usVKey;
- UCHAR uchRepeat;
- HWND hwndParent;
- POBJECT pObject;
- char *pTmp;
-
- hwndParent = WinQueryWindow(hwnd, QW_PARENT);
- pObject = (POBJECT)WinQueryWindowULong(hwndParent, 0);
- switch(msg)
- {
-
- case UM_SETFOCUS:
- WinSetFocus(hwnd, TRUE);
- WinPostMsg(hwnd, WM_MOUSEMOVE, MPFROM2SHORT(20,20), 0L);
- WinPostMsg(hwnd, WM_BUTTON1DOWN, MPFROM2SHORT(1,100), 0L);
- WinPostMsg(hwnd, WM_BUTTON1UP, MPFROM2SHORT(1,100), 0L);
- break;
-
- case WM_CHAR:
- fsKeyFlags = (USHORT)SHORT1FROMMP(mp1);
- uchRepeat = (UCHAR)CHAR3FROMMP(mp1);
- Keyboard.uchScanCode = (UCHAR)CHAR4FROMMP(mp1);
- usChar = (USHORT)SHORT1FROMMP(mp2);
- usVKey = (USHORT)SHORT2FROMMP(mp2);
- if (!(fsKeyFlags & KC_KEYUP))
- if ((fsKeyFlags & KC_CHAR) )
- {
- while (uchRepeat--)
- {
- *Keyboard.wp++ = usChar;
- if(Keyboard.wp == &Keyboard.buf[KBSIZE])
- Keyboard.wp = Keyboard.buf;
- Keyboard.cnt++;
- psignal(&Keyboard,0);
- }
- if(usChar == 0x0D)
- {
- pTmp = malloc(256);
- WinQueryWindowText(hwnd, 256, pTmp);
- strcat(pTmp, "\n\r");
- WinPostMsg(pObject->pSession->hwndSession, MLM_INSERT, MPFROMP(pTmp), MPFROMLONG(256L));
- WinSetWindowText(hwnd, "");
- return(MPFROMSHORT(TRUE));
- }
- if(!Current->ttystate.echo)
- return(MRFROMSHORT(TRUE));
- }
- else
- if (fsKeyFlags & KC_CTRL && (usChar & 0xff))
- {
- usChar &= 0xdf; /* make uppercase */
- *Keyboard.wp++ = usChar - 0x40;
- if(Keyboard.wp == &Keyboard.buf[KBSIZE])
- Keyboard.wp = Keyboard.buf;
- Keyboard.cnt++;
- psignal(&Keyboard,0);
- }
- else
- if (fsKeyFlags & KC_VIRTUALKEY && ((usChar & 0x1b) == 0x1b))
- {
- *Keyboard.wp++ = 0x1b;
- if(Keyboard.wp == &Keyboard.buf[KBSIZE])
- Keyboard.wp = Keyboard.buf;
- Keyboard.cnt++;
- psignal(&Keyboard,0);
- }
-
- return((MRESULT)(pfnEntry)(hwnd, msg, mp1, mp2));
-
- default:
- return((pfnEntry)(hwnd, msg, mp1, mp2));
- }
- return((MRESULT)FALSE);
- }
-
- void newTrace(struct session *sp)
- {
- ULONG ulPostCt;
-
- DosEnterCritSec();
- WinPostMsg(Command->hwndSession, UM_TRACE, MPFROMP(sp), MPFROMLONG(1L));
- DosResetEventSem(Curproc->sem, &ulPostCt);
- DosExitCritSec();
- DosWaitEventSem(Curproc->sem, SEM_INDEFINITE_WAIT);
- }
-
- void freeTrace(struct session *sp)
- {
- WinPostMsg(sp->hwndSession, UM_DESTROY, MPFROMLONG(0L), MPFROMLONG(0L));
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- WinPostMsg(sp->hwndFrame, WM_DESTROY, MPFROMLONG(0L), MPFROMLONG(0L));
- }
-
- void
- newscreen(struct session *sp)
- {
- PSZ pszName;
- POBJECT pObject;
- PTIB pptib;
- PPIB pppib;
- ULONG ulPostCt;
- SWP swp;
- PERRINFO pErr;
- int rc;
-
- DosGetInfoBlocks(&pptib, &pppib);
- if (sp != NULLSESSION)
- if (pptib->tib_ptib2->tib2_ultid != 1)
- {
- DosEnterCritSec();
- WinPostMsg(Command->hwndSession, UM_SESSION, MPFROMP(sp), MPFROMLONG(1L));
- DosResetEventSem(Curproc->sem, &ulPostCt);
- DosExitCritSec();
- DosWaitEventSem(Curproc->sem, SEM_INDEFINITE_WAIT);
- }
- else
- {
- pszName = malloc(strlen(sp->name) + strlen(szClientClass) + 4);
- strcpy(pszName, szClientClass);
- strcat(pszName, " - ");
- strcat(pszName, sp->name);
- sp->hwndFrame = hwndFrame = WinCreateStdWindow (HWND_DESKTOP,
- 0L,
- &flFrameFlags,
- szClientClass,
- pszName,
- 0L,
- (HMODULE)NULL,
- ID_RESOURCE,
- &sp->hwndSession) ;
- hwndCmd = sp->hwndSession;
- if (!hwndFrame)
- prtError(hab, sp->hwndFrame);
-
- pObject = (POBJECT)WinQueryWindowULong(sp->hwndSession, 0);
- WinQueryWindowPos(sp->hwndSession, &swp);
- pObject->hwndMle = WinCreateWindow(sp->hwndSession,
- WC_MLE,
- "",
- WS_VISIBLE | MLS_VSCROLL |MLS_WORDWRAP,
- 0, 0, swp.cx, swp.cy,
- sp->hwndSession,
- HWND_TOP,
- 1,
- NULL,
- NULL);
- if (!pObject->hwndMle)
- {
- prtError(hab, sp->hwndFrame);
- return;
- }
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETFONT, MPFROMP(&fat), 0L);
- rc = (int)WinSendMsg(pObject->hwndMle, MLM_SETTABSTOP, MPFROMSHORT(8 *(short)fat.lAveCharWidth), 0L);
- if (rc == 0)
- prtError(hab, sp->hwndFrame);
- WinSendMsg(pObject->hwndMle, MLM_SETBACKCOLOR, MPFROMLONG(CLR_BACKGROUND), 0L);
- WinSendMsg(pObject->hwndMle, MLM_SETTEXTLIMIT, MPFROMLONG(-1), 0L);
- if (rc == 0)
- prtError(hab, sp->hwndFrame);
- rc = WinSetFocus(HWND_DESKTOP, pObject->hwndMle);
- pfnMle = WinSubclassWindow(pObject->hwndMle, NewMleWndProc);
- if (rc == 0)
- prtError(hab, sp->hwndFrame);
- free(pszName);
- sp->ttystate.crnl = sp->ttystate.edit = sp->ttystate.echo = 1;
- pObject->pSession = sp;
- pObject->display = sp->display = newproc("display", 4096, display, 1, pObject->pSession, NULL, 0);
- }
- }
-
- void
- freescreen(struct session *sp)
- {
- if(sp == NULLSESSION || sp->screen == NULLSCREEN)
- return;
- if(sp->screen->save != NULLCHAR)
- free(sp->screen->save);
- free((char *)sp->screen);
- WinPostMsg(sp->hwndSession, UM_DESTROY, MPFROMLONG(0L), MPFROMLONG(0L));
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- WinPostMsg(sp->hwndFrame, WM_DESTROY, MPFROMLONG(0L), MPFROMLONG(0L));
- errid = WinGetLastError(hab);
- rc = ERRORIDERROR(errid);
- killproc(sp->display);
- }
-
- int kbread()
- {
- int c;
- if((c = kbchar()) == 0){
- switch(Keyboard.uchScanCode){
- case 3: /* NULL (bizzare!) */
- c = 0;
- break;
- case 61: /* F-3 key (used as line-repeat) */
- c = 2;
- break;
- case 68: /* F-10 key (used as command-mode escape) */
- c = -2;
- break;
- case 83: /* DEL key */
- c = 0x7f;
- break;
- default: /* Dunno what it is */
- c = -1;
- }
- }
- return c;
- }
-
- static int
- kbchar()
- {
- char i_state;
- char c;
-
- /*i_state = dirps();*/
- while(Keyboard.cnt == 0)
- pwait(&Keyboard);
- Keyboard.cnt--;
- /*restore(i_state);*/
- c = *Keyboard.rp++;
- if(Keyboard.rp == &Keyboard.buf[KBSIZE])
- Keyboard.rp = Keyboard.buf;
- return uchar(c);
- }
-
- void MailNotify(char *pszUser)
- {
- ERRORID err;
- int rc;
- char *pszItem;
- pszItem = strdup(pszUser);
- WinPostMsg(Command->hwndSession, UM_BMAIL, MPFROMP(pszItem), 0L);
- return;
- }
- PDDESTRUCT MakeDDEObject(PSZ pszItemName, USHORT usStatus, USHORT usFormat,
- PVOID pData, USHORT usDataLen)
- {
- PDDESTRUCT pddes;
- ULONG ulItemLength;
- PULONG pulSharedObj;
-
- if (pszItemName)
- ulItemLength = strlen(pszItemName) + 1;
- else
- ulItemLength = 0L;
- if (!DosAllocSharedMem((PVOID)&pulSharedObj,
- NULL,
- sizeof(DDESTRUCT) + ulItemLength + usDataLen,
- PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE |OBJ_GETTABLE))
- {
- pddes = (PDDESTRUCT)pulSharedObj;
- memset(pddes, '\0', sizeof(DDESTRUCT));
- pddes->cbData = usDataLen + sizeof(DDESTRUCT) + ulItemLength;
- pddes->fsStatus = usStatus;
- pddes->usFormat = usFormat;
- pddes->offszItemName = sizeof(DDESTRUCT);
- if (usDataLen && pData)
- pddes->offabData = sizeof(DDESTRUCT) + ulItemLength;
- if (pszItemName)
- strcpy(DDES_PSZITEMNAME(pddes), pszItemName);
- if (pData)
- memcpy(DDES_PABDATA(pddes), pData, usDataLen);
- return(pddes);
- }
- return((PDDESTRUCT)NULL);
- }
-
- int prtError(HAB hab, HWND hwnd)
- {
- char *pTmp, *pTmp1, *pTmp2;
- PERRINFO pErr;
- int i, rc, iOffset;
- i = 0;
- return(0); /* remove for debug */
- pErr = WinGetErrorInfo(hab);
- if (!pErr)
- return(0);
- pTmp = malloc(256);
- if (!pTmp)
- {
- WinFreeErrorInfo(pErr);
- return(-1);
- }
- pTmp1 = malloc(256);
- if (!pTmp1)
- {
- free(pTmp);
- WinFreeErrorInfo(pErr);
- return(-1);
- }
- pTmp2 = malloc(256);
- if (!pTmp2)
- {
- free(pTmp);
- free(pTmp1);
- WinFreeErrorInfo(pErr);
- return(-1);
- }
- *pTmp1 = '\0';
- iOffset = (int)*((char *)pErr + (pErr->offaoffszMsg));
- for (i = 0; i < pErr->cDetailLevel; i++)
- {
- sprintf(pTmp2, (char *)((char *)pErr + iOffset + i), pErr + pErr->offBinaryData);
- strcat(pTmp1, pTmp2);
- strcat(pTmp1, "\n");
- }
- sprintf(pTmp, "Error - %x\n%s", pErr->idError, pTmp1);
- rc = WinMessageBox(HWND_DESKTOP, hwnd, pTmp, "PMNOS - Debug", 0, MB_ICONEXCLAMATION | MB_OKCANCEL);
- WinFreeErrorInfo(pErr);
- free(pTmp);
- free(pTmp1);
- free(pTmp2);
- return(rc);
- }
-
- static void display(int i, void *v1, void *v2)
- {
- BOOL fNewLine;
- PCHAR pachBuffer;
- PCHAR pachBuffer1;
- struct session *sp;
- struct usock *up;
- int icnt, c;
- BOOL rc, fTerminate, fGathering;
- fTerminate = FALSE;
- sp = (struct session *)v1;
- up = itop((int)(sp->output));
- if (!up)
- return; /* not properly initalized */
- pachBuffer1 = malloc(500);
- rc = WinPostMsg(sp->hwndSession, UM_REFRESH, MPFROMLONG(1L), MPFROMLONG(0L));
- while(!fTerminate)
- {
- fNewLine = FALSE;
- if(sp->morewait){
- pwait(&sp->row);
- if(sp != Current || sp->row <= 0){
- /* Current changed value, or the user
- * hasn't really hit a key
- */
- continue;
- }
- /* Erase the prompt */
- do {
- rc = WinPostMsg(sp->hwndSession, UM_ERASELINE, 0L, 0L);
- if (rc == FALSE)
- DosSleep(MSPTICK);
- } while (rc == FALSE);
- }
- sp->morewait = 0;
- icnt = 0;
- pachBuffer = pachBuffer1;
- fGathering = TRUE;
- do
- {
- rc = WinPostMsg(sp->hwndSession, UM_REFRESH, 0L, 0L);
- if (rc == FALSE)
- DosSleep(MSPTICK);
- } while (rc == FALSE);
- while(fGathering)
- {
- if (icnt == 499)
- {
- fGathering = FALSE;
- break;
- }
- c = rrecvchar(sp->output);
- up->noblock = TRUE;
-
- switch (c)
- {
- case EABORT:
- fTerminate = TRUE;
- free(pachBuffer1);
- pachBuffer1 = NULL;
- break;
-
- case 0x07:
- WinAlarm(HWND_DESKTOP, WA_NOTE);
- break;
-
- case 0x0d:
- break;
-
- case '\b':
- if (icnt)
- pachBuffer1[--icnt] = ' ';
- break;
-
- case 0x0a:
- pachBuffer1[icnt++] = '\n';
- break;
-
- case '\t':
- pachBuffer1[icnt++] = c;
- break;
- case -1:
- fGathering = FALSE;
- break;
-
- default:
- if (iscntrl(c))
- break;
- pachBuffer1[icnt++] = c;
- }
- }
- if (fTerminate)
- return;
- if (icnt)
- {
- pachBuffer = malloc(icnt + 1);
- memcpy(pachBuffer, pachBuffer1, icnt);
- pachBuffer[icnt] = '\0';
- if(sp->record != NULLFILE)
- fwrite(pachBuffer, icnt, 1, sp->record);
- do
- {
- rc = WinPostMsg(sp->hwndSession, MLM_INSERT, MPFROMP(pachBuffer), MPFROMLONG(icnt));
- if (rc == FALSE)
- DosSleep(MSPTICK);
- } while (rc == FALSE);
- pachBuffer = NULL;
- /* if(sp->flowmode && fNewLine && --sp->row <= 0){
- do {
- rc = WinPostMsg(sp->hwndSession, MLM_INSERT, MPFROMP("--More--"), 8L);
- if (rc == FALSE)
- DosSleep(MSPTICK);
- sp->morewait = 1;
- } while (rc == FALSE);
- }*/
- }
- if (c == -1)
- {
- do
- {
- rc = WinPostMsg(sp->hwndSession, UM_REFRESH, MPFROMLONG(1L), MPFROMLONG(0L));
- if (rc == FALSE)
- DosSleep(MSPTICK);
- } while (rc == FALSE);
- c = pwait(up);
- if (c == EABORT)
- {
- free(pachBuffer1);
- return;
- }
- }
- }
- }
-
-